package com.xzz.finger;

/**
 * @author: hhz
 * @create: 2022-02-21 15:54
 * 剑指 Offer 28. 对称的二叉树
 **/
public class IsSymmetric {
    public static void main(String[] args) {
        TreeNode head = new TreeNode(1);
        TreeNode node1 = new TreeNode(2);
        head.right = node1;
        System.out.println(isSymmetric(head));
    }

    public static boolean isSymmetric(TreeNode root) {
        if (root == null) {
            return true;
        }
        return judge(root.left,root.right);
    }

    public static boolean judge(TreeNode node1, TreeNode node2) {
        if (node1 == null && node2 == null) {
            return true;
        }
        if (node1 == null || node2 == null || node1.val != node2.val) {
            return false;
        }
        return judge(node1.left,node2.right) && judge(node1.right,node2.left);
    }
}
